<template>
    <view :style="objColor">
        <!-- pages/code/code.wxml -->
        <view class="code_box">
            <view class="txt">请输入充电桩上的终端号</view>
            <input class="codeinput" placeholder="请输入终端编号" v-model="qcode" type="number" />
            <view class="codeBtn" @click="gores">确定</view>
            <view class="switch" @tap="goqcode">
                <image class="img" :src="(mixOtherIconList[1] && mixOtherIconList[1].icon) || 'https://oos-cn.ctyunapi.cn/front-end/static/static/switch.png'"></image>
                切换至扫码充电
            </view>
        </view>
        <!-- <u-popup :show="showTip" @close="onClose" mode="center" custom-style="padding:34rpx;background: #FFFFFF;border-radius: 16rpx;width:630rpx;">
            <view class="popupTxt">
                <image class="img" src="https://oos-cn.ctyunapi.cn/front-end/static/static/tip.png"></image>
                {{ showTitle }}
            </view>
            <view class="popupBtn">
                <view class="popupBtn1" @tap="onClose">取消</view>
                <view class="popupBtn2" @tap="onClose">确定</view>
            </view>
        </u-popup> -->
        <u-modal :show="showTip" title="提示" @confirm="onClose" @cancel="onClose" showCancelButton :confirmColor="objColor2.textColor">
            <view class="slot-content">
                <view class="popupTxt">
                    <image class="img" src="https://oos-cn.ctyunapi.cn/front-end/static/static/tip.png"></image>
                    {{ showTitle }}
                </view>
            </view>
        </u-modal>
    </view>
</template>

<script>
'use strict';

// exports.__esModule = true; // pages/code/code.ts

var scanCode = require('./../../utils/scanCode.js');

var https_1 = require('./../../api/https.js');
export default {
    components: {
    },
    data() {
        return {
            qcode: '',
            showTip: false,
            showTitle: ''
        };
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        //关闭弹窗
        onClose: function () {
            this.setData({
                showTip: false
            });
        },

        //输入桩号
        codeInput: function (e) {
            this.setData({
                qcode: e.detail.value
            });
        },

        //切换到扫码
        goqcode: function () {
            this.setData({
                qcode: ''
            });
            scanCode.stateOfCharge();
        },

        //点击确定
        gores: function () {
            var that = this; //检测是否输入二维码

            if (!this.qcode) {
                this.setData({
                    showTip: true,
                    showTitle: '桩号输入不正确,请检查后重新输入'
                });
                return;
            } // else {
            //   this.setData({
            //     showTip: true,
            //     showTitle: '链接超时，请重试'
            //   })
            // }

            https_1
                .querChargeRealy({
                    pileNo: this.qcode,
                    gunNo: -1
                })
                .then(function (res) {
                    console.log(res, 'code--查询桩详情??????');
                    if (res.code == 0) {
                        if(res.data.terminalType ===2) {
                            uni.navigateTo({
                                url: '/homeSub/pages/eBikeSiteDetail/eBikeSiteDetail?pileNo=' + that.qcode
                            });
                        } else {
                            uni.navigateTo({
                                url: '/echartsPages/pages/terminal/pileDetail/pileDetail?pileNo=' + that.qcode
                            });
                        }
                    }
                    // 站点未发布 506 || 桩未发布 507
                    else if (res.code == 506 || res.code == 507) {
                        uni.redirectTo({
                            url: '/homeSub/pages/terminal/fault/fault0131?pileText=' + res.msg
                        });
                    }
                    // 请检查品牌和终端号是否正确喔 50501 || 桩暂不开放 50502
                    else if (res.code == 50501 || res.code == 50502) {
                        that.setData({
                            showTip: true,
                            showTitle: res.msg
                        });
                    }
                    else {
                        // uni.showModal({
                        //     title: '信息提示',
                        //     content: '桩号输入不正确，请检查后重新输入',
                        //     showCancel: false
                        // });
                        that.setData({
                            showTip: true,
                            showTitle: '桩号输入不正确,请检查后重新输入'
                        });
                    }
                });
        }
    }
};
</script>
<style lang="less">
@import url(./code.less);  /* pages/code/code.wxss */

</style>
